package pro.softzhang.algo.lc700;

import java.util.PriorityQueue;

public class LC703_KthLargestElementInAStream {
    public static void main(String[] args) {

    }

    static class KthLargest {
        private PriorityQueue<Integer> heap;
        private int size;

        public KthLargest(int k, int[] nums) {
            size = k;
            heap = new PriorityQueue<>(size);
            for (int num : nums) {
                add(num);
            }
        }

        public int add(int val) {
            if(heap.size() < size) {
                heap.offer(val);
            } else if(val > heap.peek()) {
                heap.poll();
                heap.offer(val);
            }
            return heap.peek();
        }
    }

}